layui.define(
  ["laydate", "form", "echarts", "element", "days"],
  function (exports) {
    var form = layui.form,
      $ = layui.$,
      echarts = layui.echarts,
      staticType = "0",
      agenda = "2",
      indexNumber = 0,
      laydate = layui.laydate,
      days = layui.days;
    element = layui.element;
    function thatDae(str) {
      let reslut = dayjs(str, "YYYYMM").valueOf();
      let thatdate = dayjs(reslut).format("YYYY年M月");
      return thatdate;
    }
    function thatDaeM(str) {
      let reslut = dayjs(str, "YYYYMM").valueOf();
      let thatdate = dayjs(reslut).format("M");
      return thatdate;
    }
    // 统计日期
    var date = new Date(),
      year = date.getFullYear(),
      month = date.getMonth() + 1,
      date = date.getDate();
    month = month < 10 ? "0" + month : month;
    date = date < 10 ? "0" + date : date;
    var currentDate = year + "-" + month + "-" + date;
    $("#statisticalCyclStart").val(currentDate);
    $("#statisticalCyclEnd").val(currentDate);
    laydate.render({
      elem: "#statisticalCycleTime",
      range: ["#statisticalCyclStart", "#statisticalCyclEnd"],
    });
    var startDate = $("#statisticalCyclStart").val();
    var dateClosed = $("#statisticalCyclEnd").val();
    initSaverProject(startDate, dateClosed);
    inintInexFun(startDate, dateClosed, agenda);
    initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
    form.on("submit(cycleSearch)", function (data) {
      var field = data.field;
      var startDate = field.statisticalCyclStart;
      var dateClosed = field.statisticalCyclEnd;
      initSaverProject(startDate, dateClosed);
      inintInexFun(startDate, dateClosed, agenda);
      initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
      meetingPageInit(startDate, dateClosed, staticType, indexNumber);
      var userNumberT = $("#userNameList").val();
      projectTaskFun(startDate, dateClosed, userNumberT);
    });
    // 最上面的tab切换
    element.on("tab(sAnalysisTopTab)", function (data) {
      var startDate = $("#statisticalCyclStart").val();
      var dateClosed = $("#statisticalCyclEnd").val();
      if (data.index == 0) {
        initSaverProject(startDate, dateClosed);
        initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
      } else if (data.index == 1) {
        meetingPageInit(startDate, dateClosed, staticType, indexNumber);
      } else if (data.index == 2) {
        projectTaskFun(
          startDate,
          dateClosed,
          layui.sessionData("userName").key
        );
        $.ajax({
          type: "GET",
          async: true, //异步执行
          url: base_url + "/user/selectUsers",
          headers: {
            Accept: "application/json; charset=utf-8",
            Authorization: layui.sessionData("userToken").key,
          },
          success: function (data) {
            if (data.code == "200") {
              if (data.data.innerUsers != "") {
                $("#userNameList").append(
                  new Option(
                    layui.sessionData("user").key,
                    layui.sessionData("userName").key
                  )
                );
                $.each(data.data.innerUsers, function (index, item) {
                  $("#userNameList").append(
                    new Option(item.username, item.userNumber)
                  );
                });
              } else {
                $("#userNameList").append(
                  new Option(
                    layui.sessionData("user").key,
                    layui.sessionData("userNumber").key
                  )
                );
              }
              form.render("select");
            }
          },
        });
        form.on("select(userNameListFilter)", function (data) {
          projectTaskFun(startDate, dateClosed, data.value);
        });
      }
    });
    // 最上面的tab切换
    element.on("tab(projectAgendaData)", function (data) {
      var startDate = $("#statisticalCyclStart").val();
      var dateClosed = $("#statisticalCyclEnd").val();
      if (data.index == 1) {
        var agenda = "1";
        inintInexFun(startDate, dateClosed, agenda);
        initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
      } else if (data.index == 0) {
        var agenda = "2";
        inintInexFun(startDate, dateClosed, agenda);
        initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
      }
    });
    function titleTimeFun(startDate, dateClosed) {
      var date1 = new Date(startDate);
      var date2 = new Date(dateClosed);
      if (date1.getTime() == date2.getTime()) {
        $(".projectApplicationTime").html(thatDae(dateClosed));
      } else {
        $(".projectApplicationTime").html(
          thatDae(startDate) + "-" + thatDae(dateClosed)
        );
      }
    }
    function initSaverProject(startDate, dateClosed) {
      $.ajax({
        async: true,
        url: base_url + "/Statistics/saverProject",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            var saverProjectData = data.data;
            $(".rojectsNumber").html(saverProjectData.rojectsFinishNumber);
            $(".rojectsNumbering").html(
              saverProjectData.rojectsProcessingNumber
            );
            $(".createTutelageNumber").html(
              saverProjectData.createTutelageNumber
            );
            $(".uploadTutelageNumber").html(
              saverProjectData.uploadTutelageNumber
            );
            $(".createReviewNumber").html(saverProjectData.createReviewNumber);
            $(".uploadingReviewNumber").html(
              saverProjectData.uploadingReviewNumber
            );
            $(".createProgramNumber").html(
              saverProjectData.createProgramNumber
            );
            $(".uploadProgramNumber").html(
              saverProjectData.uploadProgramNumber
            );
          }
        },
      });
    }
    function inintInexFun(startDate, dateClosed, agenda) {
      titleTimeFun(startDate, dateClosed);
      $.ajax({
        async: true,
        url: base_url + "/Statistics/projectOperation",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          agenda,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            var projectOperationData = data.data;
            var projectOperationDataSum = 0;
            projectOperationData.forEach((val) => {
              projectOperationDataSum += val.value;
            });
            var projectOperationDataSum = projectOverallSumFun(
              "projectOverallSumR_" + agenda,
              projectOperationData,
              projectOperationDataSum
            );
          }
        },
      });
      $.ajax({
        async: true,
        url: base_url + "/Statistics/phaseStatistics",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          agenda,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            var phaseStatisticsData = data.data;
            var phaseStatisticsDataSum = 0;
            phaseStatisticsData.forEach((val) => {
              phaseStatisticsDataSum += val.value;
            });
            projectOverallSumFun(
              "projectOverallSumL_" + agenda,
              phaseStatisticsData,
              phaseStatisticsDataSum
            );
          }
        },
      });
      // 会议总数;
      $.ajax({
        async: true,
        url: base_url + "/meetingStatistical/countMeeting",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            var meetingSumData = data.data;
            $(".sumMeeting").html(meetingSumData.sumMeeting);
            $(".sumMeetingFile").html(meetingSumData.sumMeetingFile);
            $(".sumMeetingTime").html(meetingSumData.sumMeetingTime);
            $(".avgMeeting").html(meetingSumData.avgMeeting);
            $(".sumUserforMeeting").html(meetingSumData.sumUserforMeeting);
          }
        },
      });
      //我的任务;
      $.ajax({
        async: true,
        url: base_url + "/Statistics/projectTask",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            var projectTaskData = data.data;
            $(".myTaskSum").html(projectTaskData.sum);
          }
        },
      });
    }
    function initPageFun(
      startDate,
      dateClosed,
      staticType,
      agenda,
      indexNumber
    ) {
      titleTimeFun(startDate, dateClosed);
      element.on("tab(statisticsData)", function (data) {
        if (data.index == 1) {
          var staticType = "1",
            indexNumber = "1";
          initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
        } else if (data.index == 2) {
          var staticType = "2",
            indexNumber = "2";
          initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
        } else if (data.index == 3) {
          var staticType = "3",
            indexNumber = "3";
          initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
        } else if (data.index == 4) {
          var staticType = "4",
            indexNumber = "4";
          initPageFun(startDate, dateClosed, staticType, agenda, indexNumber);
        }
      });

      $.ajax({
        async: false,
        url: base_url + "/Statistics/projectApplication",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          type: staticType,
          agenda,
        }), //默认 0全部  1监护大纲 2、技审意见许可  3、技审意见征询}),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            projectApplicationData = data.data;
          }
        },
      });
      $.ajax({
        async: false,
        url: base_url + "/Statistics/regionalism",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          type: staticType, //默认 0全部  1监护大纲 2、技审意见许可  3、技审意见征询}),
          agenda,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            regionalism = data.data;
          }
        },
      });
      $.ajax({
        async: false,
        url: base_url + "/Statistics/line",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          type: staticType,
          agenda,
        }), //默认 0全部  1监护大纲 2、技审意见许可  3、技审意见征询}),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            StatisticsLineData = data.data;
          }
        },
      });
      // 项目申请数量统计
      $.ajax({
        async: false,
        url: base_url + "/Statistics/saverMonth",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          type: staticType,
          agenda,
        }), //默认 0全部  1监护大纲 2、技审意见许可  3、技审意见征询}),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            saverMonthData = data.data;
          }
        },
      });
      // 月度项目申请数量统计
      var myChart = echarts.init(
        document.getElementById("projectApplyStation_" + agenda + indexNumber)
      );
      var option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            textStyle: {
              color: "#fff",
            },
          },
        },
        grid: {
          top: "15%",
          left: "5%",
          bottom: "5%",
          right: "5%",
          containLabel: true,
          textStyle: {
            color: "#fff",
          },
        },
        legend: {
          top: "5%",
          right: "5%",
          textStyle: {
            color: "#90979c",
          },
          data: ["申请通过数"],
        },

        calculable: true,
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: true,
              textStyle: {
                color: "#000",
              },
              lineStyle: {
                color: "#333",
                width: 1,
              },
            },
            splitLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            splitArea: {
              show: false,
            },
            axisLabel: {
              interval: 0,
            },
            data: saverMonthData.name,
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "件",
            nameTextStyle: {
              color: "#666",
              fontSize: 16,
              fontWeight: "500",
              padding: [0, 0, 5, 0],
            },
          },
        ],
        series: [
          {
            name: "申请通过数",
            type: "bar",
            stack: "总量",
            barMaxWidth: 35,
            barGap: "10%",
            itemStyle: {
              normal: {
                color: "#3BBBBC",
                label: {
                  show: true,
                  textStyle: {
                    color: "#fff",
                  },
                  position: "inside",
                  formatter: function (p) {
                    return p.value > 0 ? p.value : "";
                  },
                },
              },
            },
            data: saverMonthData.value,
          },
        ],
      };
      myChart.setOption(option);
      // 2021年5月项目申请数(占比统计)
      proportionApply();
      function proportionApply() {
        var myChart = echarts.init(
          document.getElementById("proportionApply_" + agenda + indexNumber)
        );
        option = {
          color: [
            "#FF4343",
            "#F69846",
            "#F6D54A",
            "#45DBF7",
            "#44AFF0",
            "#4777F5",
            "#5045F6",
            "#AD46F3",
            "#F845F1",
          ],
          tooltip: {
            trigger: "item",
            formatter: "{a} <br/>{b} : {c}项,({d}%)",
            textStyle: {
              fontSize: 15,
            },
          },
          series: [
            {
              name: "项目申请数占比",
              type: "pie",
              clockwise: false,
              startAngle: 90,
              radius: "90%",
              center: ["50%", "50%"],
              hoverAnimation: false,
              roseType: "radius", //area
              data: projectApplicationData,
              label: {
                show: true,
                position: "outside",
                formatter: "{b}:{c}项,{d}%",
              },
              labelLine: {
                normal: {
                  length: 20,
                  length2: 30,
                  lineStyle: {
                    width: 1,
                  },
                },
              },
            },
          ],
        };
        myChart.setOption(option); // 为echarts对象加载数据
      }

      var myChartt = echarts.init(
        document.getElementById("applyRegion_" + agenda + indexNumber)
      );
      var colorList = [
        "#ff7f50",
        "#87cefa",
        "#da70d6",
        "#32cd32",
        "#6495ed",
        "#ff69b4",
        "#ba55d3",
        "#cd5c5c",
        "#ffa500",
        "#40e0d0",
        "#1e90ff",
        "#ff6347",
        "#7b68ee",
        "#d0648a",
        "#ffd700",
        "#6b8e23",
        "#4ea397",
        "#3cb371",
        "#b8860b",
        "#7bd9a5",
      ];
      var option = {
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            center: ["50%", "50%"],
            radius: ["35%", "60%"],
            minAngle: 10,
            avoidLabelOverlap: true,
            hoverOffset: 15,
            itemStyle: {
              color: (params) => {
                return colorList[params.dataIndex];
              },
            },
            label: {
              show: true,
              position: "outside",
              formatter: "{a|{b}：{d}%}\n{hr|}",
              rich: {
                hr: {
                  backgroundColor: "auto",
                  borderRadius: 2.5,
                  width: 0,
                  height: 0,
                  padding: [2.5, -2.5, 2.5, -2.5],
                },
                a: {
                  padding: [-35, 15, -20, 5],
                },
              },
            },

            data: regionalism,
          },
        ],
      };
      myChartt.setOption(option);
      var myCharttt = echarts.init(
        document.getElementById("lineApply_" + agenda + indexNumber)
      );
      option = {
        grid: {
          top: "15%",
          left: "5%",
          bottom: "5%",
          right: "5%",
          containLabel: true,
        },
        tooltip: {
          trigger: "item",
        },
        color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
          {
            offset: 0,
            color: "rgba(235,59,90,0.3)",
          },
          {
            offset: 1,
            color: "#EB3B5A",
          },
        ]),
        legend: {
          top: "5%",
          right: "5%",
          textStyle: {
            color: "#90979c",
          },
          data: ["申请通过数"],
        },
        animation: false,
        xAxis: [
          {
            type: "category",
            data: StatisticsLineData.name,
            axisTick: {
              alignWithLabel: true,
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              textStyle: {
                color: "#333",
              },
              margin: 30,
            },
            interval: 1,
          },
        ],
        yAxis: [
          {
            show: true,
            type: "value",
            name: "件",
            nameTextStyle: {
              color: "#666",
              fontSize: 16,
              fontWeight: "500",
              padding: [0, 0, 5, 0],
            },
          },
        ],
        series: [
          {
            name: "上部圆",
            type: "pictorialBar",
            silent: true,
            symbolSize: [40, 10],
            symbolOffset: [0, -6],
            symbolPosition: "end",
            z: 12,
            label: {
              normal: {
                show: true,
                position: "top",
                fontSize: 15,
                fontWeight: "bold",
                color: "#4EA24E",
              },
            },
            color: "#4EA24E",
            data: StatisticsLineData.value,
          },
          {
            name: "底部圆",
            type: "pictorialBar",
            silent: true,
            symbolSize: [40, 10],
            symbolOffset: [0, 7],
            z: 12,
            color: "#4EA24E",
            data: StatisticsLineData.value,
          },
          {
            name: "内层波浪",
            type: "pictorialBar",
            silent: true,
            symbolSize: [50, 15],
            symbolOffset: [0, 12],
            z: 10,
            itemStyle: {
              normal: {
                color: "transparent",
                borderColor: "#4EA24E",
                borderType: "solid",
                borderWidth: 8,
              },
            },
            data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
          },
          {
            name: "外层波浪",
            type: "pictorialBar",
            silent: true,
            symbolSize: [70, 20],
            symbolOffset: [0, 18],
            z: 10,
            itemStyle: {
              normal: {
                color: "transparent",
                borderColor: "rgba(91,252,244,0.5)",
                borderType: "solid",
                borderWidth: 5,
              },
            },
            data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
          },
          {
            name: "申请通过数",
            type: "bar",
            barWidth: "40",
            barGap: "10%", // Make series be overlap
            barCateGoryGap: "10%",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
                  {
                    offset: 0,
                    color: "rgba(210,210,210,0.3)",
                  },
                  {
                    offset: 1,
                    color: "#4EA24E",
                  },
                ]),
                opacity: 0.8,
              },
            },
            data: StatisticsLineData.value,
          },
        ],
      };
      myCharttt.setOption(option); // 为echarts对象加载数据
    }

    // 会议分类统计
    function meetingPageInit(startDate, dateClosed, staticType, indexNumber) {
      element.on("tab(meetingStatisticsData)", function (data) {
        if (data.index == 1) {
          meetingPageInit(startDate, dateClosed, "1", 1);
        } else if (data.index == 2) {
          meetingPageInit(startDate, dateClosed, "2", 2);
        } else if (data.index == 0) {
          meetingPageInit(startDate, dateClosed, "0", 0);
        }
      });
      $.ajax({
        async: false,
        url: base_url + "/meetingStatistical/meetingBar",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          type: staticType,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            meetingBarData = data.data;
          }
        },
      });
      var meetingMyChart = echarts.init(
        document.getElementById("meetingClassStatis_" + indexNumber)
      );
      // 头部菱形
      const diamondData = meetingBarData.result.reduce((pre, cur, index) => {
        pre[index] = cur.data.map(
          (el, id) => el + (pre[index - 1] ? pre[index - 1][id] : 0)
        );
        return pre;
      }, []);

      // color
      const color = [
        [
          { offset: 0, color: "#efff37" },
          { offset: 0.5, color: "#efff37" },
          { offset: 0.5, color: "#d5e700" },
          { offset: 1, color: "#d5e700" },
        ],
        [
          { offset: 0, color: "#32ffee" },
          { offset: 0.5, color: "#32ffee" },
          { offset: 0.5, color: "#00e8d5" },
          { offset: 1, color: "#00e8d5" },
        ],
        [
          { offset: 0, color: "#46c9ff" },
          { offset: 0.5, color: "#46c9ff" },
          { offset: 0.5, color: "#00b4ff" },
          { offset: 1, color: "#00b4ff" },
        ],
      ];
      let series = meetingBarData.result.reduce((p, c, i, array) => {
        p.push(
          {
            z: i + 1,
            stack: "总量",
            type: "bar",
            name: c.name,
            barGap: "-100%",
            barWidth: 30,
            data: c.data,
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                x2: 1,
                y: 0,
                y2: 0,
                colorStops: color[i],
              },
            },
          },
          {
            z: i + 10,
            type: "pictorialBar",
            symbolPosition: "end",
            symbol: "diamond",
            symbolOffset: [0, "-50%"],
            symbolSize: [30, 10],
            data: diamondData[i],
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                x2: 1,
                y: 0,
                y2: 0,
                colorStops: color[i],
              },
            },
            tooltip: { show: false },
          }
        );
        if (p.length === array.length * 2) {
          p.push({
            z: array.length * 2,
            type: "pictorialBar",
            symbolPosition: "start",
            data: meetingBarData.result[0].data,
            symbol: "diamond",
            symbolOffset: ["0%", "50%"],
            symbolSize: [30, 10],
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                x2: 1,
                y: 0,
                y2: 0,
                colorStops: color[0],
              },
            },
            tooltip: { show: false },
          });
          return p;
        }

        return p;
      }, []);

      // tooltip
      const tooltip = { trigger: "axis" };

      // legend
      const legend = {
        data: meetingBarData.result.map((item) => item.name),
        textStyle: { fontSize: 14, color: "#000" },
        itemWidth: 25,
        itemHeight: 15,
        itemGap: 15,
        bottom: "5%",
      };
      // grid
      const grid = {
        top: "10%",
        left: "5%",
        right: "5%",
        bottom: "15%",
        containLabel: true,
      };

      // xAxis
      const xAxis = {
        axisTick: { show: true },
        axisLine: { lineStyle: { color: "rgba(255,255,255, .2)" } },
        axisLabel: { textStyle: { fontSize: 12, color: "#000" } },
        data: meetingBarData.xdata.map((v) => thatDaeM(v) + "月"),
      };

      // yAxis
      const yAxis = [
        {
          show: true,
          type: "value",
          name: "个",
          nameTextStyle: {
            color: "#666",
            fontSize: 16,
            fontWeight: "500",
            padding: [0, 0, 5, 0],
          },
          textStyle: {
            fontSize: 15,
          },
        },
      ];

      // 渲染
      var option = {
        tooltip,
        xAxis,
        yAxis,
        series,
        grid,
        legend,
      };
      meetingMyChart.setOption(option);
      meetingMyChart.resize();
    }

    function projectOverallSumFun(eleId, echartData, sum) {
      var myChart = echarts.init(document.getElementById(eleId));
      option = {
        color: [
          "#6789FF",
          "#FF5896",
          "#31B5D0",
          "#FFA92A",
          "#C75FFF",
          "#71BAC1",
          "#BAC5EB",
        ],
        tooltip: {
          show: false,
          trigger: "item",
          formatter: "{b}: {c} ({d}%)",
        },
        title: [
          {
            zlevel: 55,
            text: sum,
            top: "43%",
            textAlign: "center",
            left: "38%",
            textStyle: {
              color: "#4970C8",
              fontFamily: "DINAlternate-Bold, DINAlternate",
              fontSize: 40,
              fontWeight: "600",
            },
          },
          {
            zlevel: 55,
            text: "项目总数",
            top: "53%",
            textAlign: "center",
            left: "38%",
            textStyle: {
              color: "#000000",
              fontSize: 16,
              fontWeight: "500",
            },
          },
          {
            zlevel: 55,
            text: "单位:件",
            top: "2%",
            textAlign: "center",
            left: "10%",
            textStyle: {
              color: "#666",
              fontSize: 16,
              fontWeight: "500",
            },
          },
        ],
        legend: {
          icon: `path://M881.387 297.813c38.08 65.387 57.28 136.747 57.28 214.187s-19.094 148.8-57.28 214.187c-38.187 65.28-89.92 117.12-155.2 155.2S589.44 938.667 512 938.667s-148.8-19.094-214.187-57.28c-65.28-38.08-117.013-89.814-155.306-155.307C104.427 660.8 85.333 589.44 85.333 512c0-77.333 19.094-148.693 57.28-214.187 38.08-65.28 89.814-117.013 155.307-155.306C363.2 104.533 434.56 85.333 512 85.333c77.333 0 148.693 19.094 214.187 57.28 65.28 38.187 117.013 89.92 155.2 155.2z m-217.707-47.36C617.387 223.467 566.827 209.92 512 209.92s-105.387 13.547-151.68 40.533-82.987 63.68-109.973 109.974c-26.987 46.293-40.534 96.853-40.534 151.68s13.547 105.386 40.534 151.68c26.986 46.293 63.68 82.986 109.973 109.973 46.293 26.987 96.853 40.533 151.68 40.533s105.387-13.546 151.68-40.533c46.293-26.987 82.987-63.68 109.973-109.973 26.987-46.294 40.534-96.854 40.534-151.68s-13.547-105.387-40.534-151.68c-27.093-46.294-63.786-82.987-109.973-109.974z`,
          orient: "vertical",
          itemWidth: 16,
          itemHeight: 16,
          right: "12%",
          top: "center",
          align: "left",
          itemGap: 20,
          formatter: function (name) {
            let target, percent;
            for (let i = 0; i < echartData.length; i++) {
              if (echartData[i].name === name) {
                target = echartData[i].value;
              }
            }
            let arr = [" {a|" + name + "}", " {b|" + target + "}"];
            return arr;
          },
          textStyle: {
            rich: {
              a: {
                fontSize: 15,
                width: 90,
                color: "#000",
                padding: [0, 0, 0, 10],
              },
              b: {
                fontSize: 21,
                color: "#4970C8",
                // fontWeight: 600,
                padding: [0, 0, 0, 0],
              },
            },
          },
        },
        toolbox: {
          show: false,
        },
        series: [
          {
            name: "",
            type: "pie",
            radius: [0, 160],
            center: ["38%", "50%"],
            label: {
              show: false,
            },
            itemStyle: {
              normal: {
                color: "#fff",
                shadowBlur: 15,
                shadowColor: "#9CA6F3",
              },
            },
            hoverAnimation: false,
            tooltip: {
              show: false,
            },
            pointer: {
              show: false,
            },
            clickable: false,
            data: [100],
          },
          {
            name: "",
            type: "pie",
            radius: [120, 135],
            center: ["38%", "50%"],
            zlevel: 100,
            label: {
              normal: {
                show: false,
              },
            },
            hoverAnimation: true,
            tooltip: {
              show: true,
            },
            hoverOffset: 2,
            data: echartData,
          },
          {
            name: "",
            type: "pie",
            radius: [0, 85],
            center: ["38%", "50%"],
            zlevel: 50,
            label: {
              show: false,
            },
            itemStyle: {
              normal: {
                color: new echarts.graphic.RadialGradient(
                  0.5,
                  0.5,
                  0.7,
                  [
                    {
                      offset: 0.5,
                      color: "#ffffff",
                    },
                    {
                      offset: 1,
                      color: "#ffffff",
                    },
                  ],
                  false
                ),
                shadowBlur: 15,
                shadowColor: "#9CA6F3",
              },
            },
            tooltip: {
              show: false,
            },
            hoverAnimation: false,
            pointer: {
              show: false,
            },
            clickable: false,
            data: [100],
          },
        ],
      };
      myChart.setOption(option);
    }
    // 我的任务
    function projectTaskFun(startDate, dateClosed, userNumberT) {
      $.ajax({
        async: false,
        url: base_url + "/Statistics/projectParticipants",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          name: userNumberT,
        }), //默认 0全部 1、技审意见许可  2、技审意见征询}),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            projectParticipantsD = data.data;
          }
        },
      });
      $.ajax({
        async: false,
        url: base_url + "/Statistics/statisticalWork",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        data: JSON.stringify({
          startDate,
          dateClosed,
          name: userNumberT,
        }),
        dataType: "json",
        success: function (data) {
          if (data.code == "200") {
            statisticalWorkData = data.data;
          }
        },
      });

      // 受理项目参与情况
      var projectAcceptanceMyChart = echarts.init(
        document.getElementById("projectAcceptance")
      );
      var titleArr = [],
        elementsArr = [],
        seriesArr = [];
      projectParticipantsD.forEach(function (item, index) {
        titleArr.push({
          text:
            "{a|" +
            item.value +
            "}" +
            "\n" +
            "{b|" +
            (index !== 2 ? "件" : "个") +
            "}",
          left: index * 34 + 14.5 + "%",
          y: "42%",
          textStyle: {
            rich: {
              a: {
                fontSize: 30,
                color: "#e4ff00",
                fontWeight: "600",
              },
              b: {
                color: "#fff",
                fontSize: 16,
                fontWeight: "500",
                padding: [5, 0, 0, 0],
              },
            },
          },
        });
        elementsArr.push(
          {
            type: "image",
            z: 4,
            style: {
              image:
                "",
              width: 121,
              height: 120,
            },
            left: index * 34 + 11.5 + "%",
            top: "36%",
            silent: true,
          },
          {
            type: "line",
            z: 4,
            style: {
              fill: "#3b4559",
              stroke: "#3b4559",
              lineWidth: 2,
            },
            shape: {
              x1: 120,
              y1: 0,
            },
            left: index * 34.5 + 11.5 + "%",
            bottom: "15%",
            silent: true,
          },
          {
            type: "text",
            z: 4,
            style: {
              text: item.name,
              font: '15px "STHeiti", sans-serif',
              color: "#0076ef",
            },
            silent: true,
            left: index * 35 + 11.5 + "%",
            bottom: "8%",
          }
        );
        seriesArr.push(
          {
            type: "gauge",
            radius: "60%",
            center: [index * 34 + 15.5 + "%", "48%"],
            clockwise: false,
            startAngle: "90",
            endAngle: "-269.9999",
            splitNumber: 40,
            detail: {
              offsetCenter: [0, -20],
              formatter: " ",
            },
            pointer: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: [
                  [0, "#173c5e"],
                  [
                    item.value / item.sum,
                    new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                      {
                        offset: 0,
                        color: "#22beff",
                      },
                      {
                        offset: 0.3,
                        color: "#22baf8",
                      },
                      {
                        offset: 1,
                        color: "#173c5e",
                      },
                    ]),
                  ],
                  [1, "#173c5e"],
                ],
                width: 30,
                shadowColor: "rgba(33, 174, 234, 0)",
                shadowBlur: 0,
              },
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            axisLabel: {
              show: false,
            },
          },

          {
            type: "pie",
            radius: ["44%", "48%"],
            center: [index * 34 + 15.5 + "%", "48%"],
            hoverAnimation: false,
            clockWise: false,
            itemStyle: {
              normal: {
                color: "#0C355E",
              },
            },
            label: {
              show: false,
            },
            data: _dashed(),
          },
          {
            type: "pie",
            radius: ["70%", "71.5%"],
            center: [index * 34 + 15.5 + "%", "48%"],
            hoverAnimation: false,
            clockWise: false,
            itemStyle: {
              normal: {
                shadowBlur: 20,
                shadowColor: "rgba(0, 118, 239,1)",
                color: "#0076EF",
              },
            },
            label: {
              show: false,
            },
            data: [100],
          },
          {
            type: "pie",
            radius: ["61%", "61.5%"],
            center: [index * 34 + 15.5 + "%", "48%"],
            hoverAnimation: false,
            clockWise: false,
            itemStyle: {
              normal: {
                shadowBlur: 0,
                shadowColor: "rgba(0, 118, 239,0.5)",
                color: "#0076ef",
              },
            },
            label: {
              show: false,
            },
            data: [100],
          },
          {
            type: "pie",
            radius: ["68%", "69.5%"],
            center: [index * 34 + 15.5 + "%", "48%"],
            hoverAnimation: false,
            clockWise: false,
            itemStyle: {
              normal: {
                shadowBlur: 0,
                shadowColor: "rgba(0, 255, 255,1)",
                color: "rgba(2, 33, 64,.6)",
              },
            },
            label: {
              show: false,
            },
            data: [100],
          }
        );
      });
      option = {
        title: titleArr,
        graphic: { elements: elementsArr },

        series: seriesArr,
      };
      projectAcceptanceMyChart.setOption(option);
      projectAcceptanceMyChart.resize();
      //审核工作统计
      var auditWorkStatisMyChart = echarts.init(
        document.getElementById("auditWorkStatis")
      );
      var titleArr = [],
        seriesArr = [];
      colors = [
        ["#389af4", "#dfeaff"],
        ["#ff8c37", "#ffdcc3"],
        ["#ffc257", "#ffedcc"],
        ["#fd6f97", "#fed4e0"],
        ["#a181fc", "#e3d9fe"],
      ];
      statisticalWorkData.forEach(function (item, index) {
        titleArr.push({
          show: true,
          text: item.name,
          x: index * 35 + 14.5 + "%",
          y: "80%",
          z: 8,
          textAlign: "center",
          textStyle: {
            color: "#333",
            fontSize: 20,
            fontWeight: "normal",
          },
        });
        seriesArr.push(
          {
            name: "内部（环形）进度条",
            type: "gauge",
            center: [index * 34 + 15.5 + "%", "50%"],
            radius: "60%",
            splitNumber: 10,
            axisLine: {
              lineStyle: {
                color: [
                  [100 / 100, "#458EFD"],
                  [1, "#FFFFFF"],
                ],
                width: 14,
              },
            },
            axisLabel: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            pointer: {
              show: false,
            },
          },
          {
            name: "外部刻度",
            type: "gauge",
            center: [index * 34 + 15.5 + "%", "50%"],
            radius: "80%",
            min: 0, //最小刻度
            max: 100, //最大刻度
            splitNumber: 10, //刻度数量
            startAngle: 225,
            endAngle: -45,
            axisLine: {
              show: true,
              // 仪表盘刻度线
              lineStyle: {
                width: 2,
                color: [[1, "#FFFFFF"]],
              },
            },
            //仪表盘文字
            axisLabel: {
              show: true,
              color: "#868FDF",
              distance: 25,
              formatter: function (v) {
                switch (v + "") {
                  case "0":
                    return "0";
                  case "10":
                    return "10";
                  case "20":
                    return "20";
                  case "30":
                    return "30";
                  case "40":
                    return "40";
                  case "50":
                    return "50";
                  case "60":
                    return "60";
                  case "70":
                    return "70";
                  case "80":
                    return "80";
                  case "90":
                    return "90";
                  case "100":
                    return "100";
                }
              },
            }, //刻度标签。
            axisTick: {
              show: true,
              splitNumber: 7,
              lineStyle: {
                color: "#3082FE", //用颜色渐变函数不起作用
                width: 2,
              },
              length: -8,
            }, //刻度样式
            splitLine: {
              show: true,
              length: -20,
              lineStyle: {
                color: "#458EFD", //用颜色渐变函数不起作用
              },
            }, //分隔线样式
            detail: {
              show: false,
            },
            pointer: {
              show: false,
            },
          },
          /*内部*/
          {
            type: "pie",
            radius: ["0", "40%"],
            center: [index * 34 + 15.5 + "%", "50%"],
            z: 8,
            hoverAnimation: false,
            data: [
              {
                name: "检查进度",
                value: item.value,
                itemStyle: {
                  normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      {
                        offset: 0,
                        color: "#3398ff",
                      },
                      {
                        offset: 1,
                        color: "#7db0fd",
                      },
                    ]),
                  },
                },
                label: {
                  normal: {
                    formatter: function (params) {
                      return params.value + "\n" + "{a|份}";
                    },
                    rich: {
                      a: {
                        color: "#fff",
                        fontSize: 16,
                        fontWeight: "500",
                        padding: [5, 0, 0, 0],
                      },
                    },
                    fontSize: 30,
                    color: "#e4ff00",
                    fontWeight: "600",
                    position: "center",
                    show: true,
                  },
                },
                labelLine: {
                  show: false,
                },
              },
            ],
          },
          /*外一层*/
          {
            type: "pie",
            radius: "45%",
            startAngle: 220,
            endAngle: -40,
            hoverAnimation: false,
            center: [index * 34 + 15.5 + "%", "50%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
            },
            labelLine: {
              show: false,
            },
            data: [
              {
                value: 1,
                itemStyle: {
                  normal: {
                    color: "#8DC4FD",
                  },
                },
              },
            ],
          },
          //外二层圈
          {
            type: "pie",
            radius: "50%",
            center: [index * 34 + 15.5 + "%", "50%"],
            avoidLabelOverlap: false,
            z: 0,
            hoverAnimation: false,
            label: {
              show: false,
            },
            labelLine: {
              show: false,
            },
            data: [
              {
                value: 1,
                itemStyle: {
                  normal: {
                    color: "#e3edf8",
                  },
                },
              },
            ],
          }
        );
      });

      option = {
        backgroundColor: "#fff",
        title: titleArr,
        series: seriesArr,
      };
      auditWorkStatisMyChart.setOption(option);
      auditWorkStatisMyChart.resize();
    }
    function _dashed() {
      let projectParticipantsD = [];
      for (var i = 0; i < 100; i++) {
        if (i % 2 === 0) {
          projectParticipantsD.push({
            name: (i + 1).toString(),
            value: 10,
            itemStyle: {
              normal: {
                color: "rgb(0,118,239,0.5)",
              },
            },
          });
        } else {
          projectParticipantsD.push({
            name: (i + 1).toString(),
            value: 50,
            itemStyle: {
              normal: {
                color: "rgb(0,0,0,0)",
                borderWidth: 1,
                borderColor: "rgb(0,118,239,1)",
              },
            },
          });
        }
      }
      return projectParticipantsD;
    }
    // function doing() {
    //   let option = projectAcceptanceMyChart.getOption();
    //   option.series[1].startAngle = option.series[1].startAngle - 1;
    //   projectAcceptanceMyChart.setOption(option);
    // }
    // function startTimer() {
    //   timer = setInterval(doing, 100);
    // }
    // setTimeout(startTimer, 0);
    exports("statisticalAnalysis", {});
  }
);
